<%-- 
    Document   : question-manage-addto-exam
    Created on : Feb 16, 2012, 2:56:08 PM
    Author     : lab
--%>

<%@page import="dao.QuestionSetDAO"%>
<%@page import="util.SharingUtil"%>
<%@page import="java.util.ArrayList"%>
<%@page import="dto.Question"%>
<%@page import="dao.QuestionDAO"%>
<%
    /* try {
    int id = Integer.parseInt(request.getParameter("id"));
    QuestionDAO daoQuestion = new QuestionDAO();
    Question q = daoQuestion.getQuestion(id);
    boolean existed = false;
    ArrayList<Question> list = new ArrayList<Question>();
    Object obj = session.getAttribute("question-list");
    if (obj != null) {
    list = (ArrayList<Question>) obj;
    }
    for (Question question : list) {
    if (question.getId() == id) {
    existed = true;
    break;
    }
    }
    if (!existed) {
    list.add(q);
    session.setAttribute("question-list", list);
    out.println("Question is added to exam");
    } else {
    out.println("Question already been in list");
    }
    
    } catch (NumberFormatException ex) {
    out.println("Question cannot be added to exam");
    }*/
    int questionId = Integer.parseInt(request.getParameter("id"));
    int examId = SharingUtil.getCurrentExam(session).getId();
    if (examId > 0) {
        QuestionSetDAO daoQS = new QuestionSetDAO();
        int eff = daoQS.create(examId, questionId);
        if (eff > 0) {
            out.println("Question is added to exam");
        } else if (eff == 0) {
            out.println("Question already in the exam");
        } else {
            out.println("Action failed");
        }
    }else{
        out.println("Please select an exam");
    }
%>